package com.suqiu.qqrobot.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.suqiu.qqrobot.common.log.annotation.LogMgr;
import com.suqiu.qqrobot.model.Message;
import com.suqiu.qqrobot.model.QingyuanModel;
import com.suqiu.qqrobot.model.TextMessage;
import com.suqiu.qqrobot.service.AiChatService;
import com.suqiu.qqrobot.utils.HttpUtil;
import org.springframework.stereotype.Service;

@LogMgr
@Service("qingYuanModelService")
public class QingYuanModelService implements AiChatService<String, String> {

    static final String URL = "http://api.qingyunke.com/api.php";

    @Override
    public Message<String> chat(String sessionId, String question) {
        String result = HttpUtil.get(URL.concat("?key=free&appid=0&msg=").concat(question));
        QingyuanModel qingyuanModel = JSONObject.parseObject(result, QingyuanModel.class);
        Message<String> message = new TextMessage();
        message.setMessage(qingyuanModel.getContent());
        return message;
    }
}
